<template>
  <div class="app">
    <el-container>
      <el-aside class="aside">
        <div class="logo">
          <img src="./assets/system.png" />
          <div class="logo_t">Vue2开发测试系统</div>
        </div>
        <el-menu
          :default-active="active"
          background-color="#03152a"
          text-color="#fff"
          active-text-color="#409EFF"
          class="menu"
          @select="handleSelect"
        >
          <el-menu-item index="0">
            <i class="el-icon-s-home"></i>
            <span slot="title">Home</span>
          </el-menu-item>
          <el-menu-item index="1">
            <i class="el-icon-mobile"></i>
            <span slot="title">mutations</span>
          </el-menu-item>
          <el-menu-item index="2">
            <i class="el-icon-setting"></i>
            <span slot="title">测试</span>
          </el-menu-item>
          <el-menu-item index="3">
            <i class="el-icon-document"></i>
            <span slot="title">表格</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header class="header">
          <span>Vue2开发测试系统</span>
          <img src="./assets/avatar.jpg" />
        </el-header>
        <el-main class="main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      active: '0',
    };
  },
  mounted() {
    const index = localStorage.getItem('routeIndex') || '0';
    this.active = index;
    const routes = ["/", "/mutations", "/test", "/table"];
    const targetRoute = routes[this.active];
    this.$router.push(targetRoute);
  },
  methods: {
    handleSelect(index) {
      const routes = ["/", "/mutations", "/test", "/table"];
      this.active = index;
      const targetRoute = routes[this.active];
      localStorage.setItem("routeIndex", this.active);
      // 如果目标路由与当前路由不同才进行跳转
      if (this.$route.path !== targetRoute) {
        this.$router.push(targetRoute);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.app {
  height: 100vh;
  overflow: hidden;
  .aside {
    width: 200px;
    margin: 0;
    padding: 0;
    .logo {
      height: 60px;
      background-color: #03152a;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 24px;
        height: 24px;
      }
      .logo_t {
        color: #fff;
        font-size: 18px;
        font-weight: 400;
        margin-left: 10px;
        white-space: nowrap;
      }
    }
    .menu {
      width: 200px;
      height: 100vh;
      user-select: none;
    }
  }
  .header {
    color: #fff;
    background-color: #03152a;
    display: flex;
    justify-content: space-between;
    align-items: center;
    img {
      width: 44px;
      height: 44px;
      border-radius: 50%;
    }
  }
  .main {
  }
}
.el-aside {
  width: 200px !important;
}
.el-menu {
  border-right: 1px solid #03152a;
}
</style>
